package com.espirit.finance.core;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.espirit.eap.util.StatGenericJPAService;
import com.googlecode.cswish.annotation.ParamScope;
import com.googlecode.cswish.model.PageElements;
import com.googlecode.cswish.model.PageInfo;
import com.googlecode.cswish.model.ParameterMap;
import com.googlecode.cswish.model.Reference;
import com.googlecode.cswish.oosearch.QLInfo;
import com.googlecode.cswish.struts.spring.SearchCallback;

@Service
public class AcctService {
	@Resource
	protected StatGenericJPAService genericService;
	
	public  PageInfo search(ParameterMap model, int start, int limit,
    		String sort, String dir, boolean newSearch, Reference<QLInfo> qlInfoRef,
    		@ParamScope(visible=false, value="#ps")PageElements ps ,boolean fromMenu,
    		Reference<Integer> parentId) {
		SearchCallback searchCallback = genericService.createDefaultSearchCallback(model.getModelName(), model, "a.nbr", "asc");
		PageInfo results = genericService.search(model, start, limit, sort, dir, true, qlInfoRef, searchCallback, true, false);
		return results;
	}
	
	public void _update(Acct model, @ParamScope(visible=false, value="#ps")PageElements ps){
		Acct acct = genericService.load(model);
		if (acct != null){
			boolean readOnly = !acct.safeChildren().isEmpty();
			ps.setElementReadOnly("model.strategy", readOnly);
		}
		genericService.view(model);
	}
}
